/*	kd:
	This just checks if the mouse is hovering over a button and clicking it,
	or any cursor, but typically mouse. */

struct Gcs_UiHandler play {
	Array <float>        m_button_x;
	Array <float>        m_button_y;
	Array <float>        m_button_rad;
	// Array <Gcs_Button>   m_button_handler;
	Array <uint>         m_button_shortcut;
	uint                 m_buttons;
	
	/*	Extra tracking data. */
	Array <bool>         m_was_hovered;
	
	uint AddButton
	(float x, float y, float rad, uint shortcut = 0) {
		// if(handler) {
			m_button_x.            push(x);
			m_button_y.            push(y);
			m_button_rad.          push(rad);
			// m_button_handler.      push(handler);
			m_button_shortcut.     push(shortcut);
			m_was_hovered.         push(false);
		// }
		return m_buttons++;
	}
	
	/*	In OOP I presume you'd make a class with virtual callback functions that
		contain a handle to what the buttons are supposed to operate on, in
		order to maximise usage for many UI clients.
		
		We use a pencil. */
	void HandleClickyShopStuff
	(Gc_Shop shop, float x, float y, bool click, bool alt_click) {
		float len;
		
		for(uint i = 0; i < m_buttons; i++) {
			len = max(abs(x - m_button_x [i]), abs(y - m_button_y [i]));
			
			if(len <= m_button_rad [i]) {
				if(click) {
					// m_button_handler [i].OnClick(shop);
					shop.OnButtonClick(i);
				}
				
				else if(alt_click) {
					// m_button_handler [i].OnAltclick(shop);
					shop.OnButtonAltClick(i);
				}
				
				else if(!m_was_hovered [i]) {
					// m_button_handler [i].OnHover(shop);
					shop.OnButtonHover(i);
					m_was_hovered [i] = true;
				}
				
				// m_button_handler [i].WhileHover(shop);
			}
			
			else if(m_was_hovered [i]) {
				// m_button_handler [i].OnDehover(shop);
				shop.OnButtonDehover(i);
				m_was_hovered [i] = false;
			}
		}
	}
	
	/*	Buttons will be few enough that O(n) ops like these don't matter. */
	void HandleShortcuts (uint input, Gc_Shop shop) {
		if(!shop) {
			return;
		}
		
		for(uint i = 0; i < m_buttons; i++) {
			if(input & m_button_shortcut [i]) {
				// m_button_handler [i].OnClick(shop);
				shop.OnButtonClick(i);
			}
		}
	}
}

/*	kd:
	Button stuff. The buttons are just bare interfaces to fit actions into and
	don't have any other info. The UI handles the stuff pertaining to actually
	finding out if a button was pressed.
	
	It has quite a lot of benefits to do it that way, mainly I don't have to
	pass a lot of data around.
	
	Normally you'd do this with hooks or something, but managing data in zs is
	a nightmare and a half, so... */

/* class Gcs_Button {
	virtual void OnHover      (Gc_Shop shop) {}
	virtual void OnDehover    (Gc_Shop shop) {}
	virtual void WhileHover   (Gc_Shop shop) {}
	virtual void OnClick      (Gc_Shop shop) {}
	virtual void OnAltclick   (Gc_Shop shop) {}
} */

/*	kd:
	Sprite base names and generation by lamp count. */
